package com.berchen.offer;

import java.util.ArrayList;

/**
 * 二叉树进行镜像翻转
 */
public class Test02 {

    public static void main(String[] args){

        TreeNode root=new TreeNode(8);
        TreeNode node6=new TreeNode(6);
        TreeNode node10=new TreeNode(10);
        TreeNode node5=new TreeNode(5);
        TreeNode node7=new TreeNode(7);
        TreeNode node9=new TreeNode(9);
        TreeNode node11=new TreeNode(11);
        node6.left=node5;
        node6.right=node7;
        node10.left=node9;
        node10.right=node11;
        root.left=node6;
        root.right=node10;

        Test02 test02 = new Test02();
        TreeNode mirror = test02.Mirror(root);

        test02.innOrder(mirror);
    }
    /**
     * 中序遍历
     * @param node
     */
    public void innOrder(TreeNode node ){

        if(node==null){
            return;
        }
        innOrder(node.left);
        System.out.println(node);
        innOrder(node.right);
    }
    public TreeNode Mirror (TreeNode pRoot) {
        // write code here
        if(pRoot==null){
            return null;
        }
        TreeNode left=pRoot.left;
        TreeNode right=pRoot.right;
        pRoot.left=Mirror(right);
        pRoot.right=Mirror(left);;
        return pRoot;
    }
}
